package com.douqu.game.main.server;

import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.factory.LoadFactory;
import com.douqu.game.core.factory.PlatformFactory;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.main.gui.MainFrame;

/**
 * Created by bean on 2017/7/27.
 */
public class LoadManager {


    /**
     * 最后更新时间
     */
    public static long lastUpdateTime;

    /**
     * 是否正在加载配置
     */
    public static boolean loading = false;

    /**
     * 是否在热更
     */
    public static boolean updating = false;


    public static void testLoad(String path)
    {
        LogUtils.info("Test Load Start-------------------------------------------");

        DataFactory.getInstance(true).clearData();

        LoadFactory.loadGameObject(path);

        DataFactory.getInstance(true).checkConfig();

        for(String error : DataFactory.getInstance(true).getErrorList())
        {
            MainFrame.println(error);
        }

        LogUtils.info("Test Load End---------------------------------------------");
    }

    private static void loadGameObject()
    {
        DataFactory.getInstance().clearData();

        LoadFactory.loadGameObject(PlatformFactory.CONFIG_PATH);

        DataFactory.getInstance().init();

        StoreManager.getInstance().initStore();
    }


    public static void ServerStartLoad()
    {
        loadGameObject();

        LoadFactory.loadConfig();

        SpringContext.showConfig();

        for(String error : DataFactory.getInstance().getErrorList())
        {
            MainFrame.println(error);
        }
    }

    public static void GMLoad()
    {
        loading = true;

        LogUtils.warn("GM Load Start ----------------------------------------------");

        loadGameObject();

        if(DataFactory.currentTime > 0)
            lastUpdateTime = DataFactory.currentTime;
        else
            lastUpdateTime = System.currentTimeMillis();

        for(String error : DataFactory.getInstance().getErrorList())
        {
            MainFrame.println(error);
        }

        LogUtils.warn("GM Load End ------------------------------------------------");
        loading = false;
    }




}
